package com.summer.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.summer.R;
import com.summer.edu.entity.Course;
import com.summer.edu.entity.Teacher;
import com.summer.edu.service.CourseService;
import com.summer.edu.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {
    @Autowired
    private CourseService courseService;
    @Autowired
    private TeacherService teacherService;
    @GetMapping("index")
    public R index(){
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<Course> courselist = courseService.list(wrapper);

        QueryWrapper<Teacher> twrapper = new QueryWrapper<>();
        twrapper.orderByDesc("id");
        twrapper.last("limit 4");
        List<Teacher> teacherlist = teacherService.list(twrapper);

        return R.ok().data("Courselist",courselist).data("teacherlist",teacherlist);
    }
}
